class Solution {
public:
    int strStr(string haystack, string needle) {
        int main = 0;
        int sub = 0;
        while(main < haystack.size()){
            if(haystack[main] == needle[sub]){
                main = main + 1;
                sub = sub + 1;
            } else {
                main = main - sub + 1;
                sub = 0;
            }

            if(sub == needle.length()){
                return main - sub;
            }
        }

        return -1;
    }
};